package org.sdnstproject.interlayer.OF13Protocal;

import java.util.HashMap;
import org.projectfloodlight.openflow.types.U32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBuf;

public class FuFeaturesRequest {
	private static final Logger log = LoggerFactory.getLogger(FuFeaturesRequest.class);
    /**version 类型:byte 默认值: 1.3*/
    public byte version = 4;
    /**type 类型:byte 默认值:0x5*/
    public byte type = 0x5;
    /**length 类型:short 默认值:8*/
    public short length = 8;
    /**xid 类型:long 默认值: 0x0L*/
    public long xid = 0x0L;
    
    public FuFeaturesRequest() {
    	
    }
    /**将FuFeaturesRequest对象写入ByteBuf*/
	public FuFeaturesRequest(ByteBuf bb) {
		// fixed value property version == 4
        this.version = bb.readByte();
        // fixed value property type
        this.type = bb.readByte();
        if(type != (byte) 0x5)
            log.info("Wrong type: Expected=OFType.FEATURES_REQUEST(5), got="+type);
        this.length = bb.readShort();
        this.xid = U32.f(bb.readInt());
    }
    
    /**将FuFeaturesRequest对象写入ByteBuf*/
	public void writeTo(ByteBuf bb) {
        // fixed value property version 
        bb.writeByte(this.version);
        // fixed value property type 
        bb.writeByte((byte) 0x5);
        // fixed value property length
        bb.writeShort(this.length);
        bb.writeInt(U32.t(this.xid));
    }

	public FuFeaturesRequest setVersion(byte version) {
		this.version = version;
		return this;
	}

	public FuFeaturesRequest setType(byte type) {
		this.type = type;
		return this;
	}

	public FuFeaturesRequest setLength(short length) {
		this.length = length;
		return this;
	}

	public FuFeaturesRequest setXid(long xid) {
		this.xid = xid;
		return this;
	}
	
	/**记录FuFeaturesRequest字段和其类型映射*/
    public HashMap<String, String> FeaturesRequestMsgFields = new HashMap<String, String>() {
		{
			put("version","byte");
			put("type","byte");
			put("length","short");
			put("xid","long");
		}
    };
    
    @Override
    public String toString() {
        StringBuilder b = new StringBuilder("OFFeaturesRequestVer13(");
        b.append("version=").append(version);
        b.append(", ");
        b.append("type=").append(type);
        b.append(", ");
        b.append("length=").append(length);
        b.append(", ");
        b.append("xid=").append(xid);
        b.append(")");
        return b.toString();
    }

}

